package com.example.dqdq.lzyim_asm_tvapp.https;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import org.xutils.x;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;

/**
 * Created by DQDQ on 16/8/18.
 */
public class HttpManger {

    private  Context context;
    private  String  url;
    private  String  paramsValue;
    private  String  paramsName;
    public HttpManger(Context context,String url,String paramsValue,String paramsName)
    {
        this.context=context;
        this.url=url;
        this.paramsValue=paramsValue;
        this.paramsName=paramsName;
    }
    public HttpManger()
    {

    }

    public static RequestParams getParams(final String url,final String paramsName,final String paramsValue)
    {
        RequestParams params = new RequestParams(url);
        params.addQueryStringParameter(paramsName, paramsValue);

        return params;

    }

    public void sendHttp(){
        RequestParams params = new RequestParams(url);
        params.addQueryStringParameter(paramsName, paramsValue);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Toast.makeText(x.app(), result, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();
            }

            @Override
            public void onCancelled(Callback.CancelledException cex) {
                Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onFinished() {

            }
        });
    }
}
